<template>
    <el-container class="home-container">

        <el-header>
            <div>
<!--          logo      <img src="../assets/logo.png">-->
                <span>后台管理系统</span>
            </div>
            <el-button type="info" @click="logout">退出</el-button>
        </el-header>

        <el-container>
            <el-aside :width="isCollapse ? '64px' : '200px'">
                <div class="toggle-button" @click="toggleCollapse">|||</div>
                <el-menu
                        default-active="2"
                        class="el-menu-vertical-demo"
                        @open="handleOpen"
                        @close="handleClose"
                        background-color="#333744"
                        text-color="#fff"
                        active-text-color="#409BFF"
                        :unique-opened="true"
                        :collapse="isCollapse"
                        :collapse-transition="false"
                        :router="true"
                >
                    <!--一级菜单-->
                    <el-submenu :index="item.id + ''" v-for="item in menulist" :key="item.id">
                        <!--一级菜单的模板-->
                        <template slot="title">
                            <i class="el-icon-location"></i>
                            <span>{{item.authName}}</span>
                        </template>

                       <!--二级菜单-->
                        <el-menu-item :index="'/'+subItem.path"  v-for="subItem in item.children" :key="subItem.id">
                            <template slot="title">
                                <i class="el-icon-location"></i>
                                <span>{{subItem.authName}}</span>
                            </template>
                        </el-menu-item>
                    </el-submenu>

                </el-menu>
            </el-aside>
            <el-main>
                <router-view></router-view>
            </el-main>
        </el-container>

    </el-container>

</template>

<script>
    export default {
        data(){
            return{
                /*左侧菜单栏数据*/
                menulist: [],
                isCollapse: false
            }
        },
        created() {
            this.getMenuList();
        },
        methods: {

            logout() {
                window.sessionStorage.clear();
                this.$router.push("/login");
            },
            /*获取所有的菜单*/
            getMenuList() {
                var that = this;
                this.$http.get('menus').then(function (e) {
                    if (e.data.meta.status !== 200){
                        that.$message.error(e.data.meta.msg);
                    }else {
                        that.menulist = e.data.data;
                    }
                })
            },

            toggleCollapse() {
                this.isCollapse = ! this.isCollapse
            }
        }
    }
</script>

<style scoped>

    .home-container{
        height: 100%;
    }


    .el-header{
        background-color: #373d41;
        display: flex;
        justify-content: space-between;
        align-items: center;
        color: #fff;
        font-size: 20px;
        font-weight: 600;
    }

    .el-aside{
        background-color: #333744;

    }

    .el-aside .el-menu {
        border-right: none;
    }

    .el-main{
        background-color: #EAEDF1;
    }
    .toggle-button{
        background-color: #4A5064;
        font-size: 10px;
        line-height: 24px;
        color: #fff;
        text-align: center;
        letter-spacing: 0.2em;
    }


</style>